package xyz.jangle.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 日期转字符串和 字符串转日期
 * @author Administrator
 *
 */
public class SimpleDateFormatDemo {

	public static void main(String[] args) throws ParseException {
		
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 解析日期字符串
        String dateString = "2024-11-26";
        Date date = sdf.parse(dateString);	//字符串转日期
        // 打印解析后的日期
        System.out.println(date.getTime());
        
        /*
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 解析日期字符串
        String dateString2 = "2024-11-26 10:10:10";
        Date date2 = sdf2.parse(dateString2);
        // 打印解析后的日期
        System.out.println(date2);
         */
        
        // 日期转字符串
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
        String format = sdf2.format(new Date());
        System.out.println(format);
        Date today = new Date();
        Long time = today.getTime() -86400000*5;
        Date yesterday = new Date(time);
        System.out.println(sdf2.format(yesterday));
        
        SimpleDateFormat format2 = new SimpleDateFormat("dd/MM/yy");
        String dateStr = format2.format(new Date());
        System.out.println(dateStr);
        SimpleDateFormat format3 = new SimpleDateFormat("HH:mm:ss");
        String timeStr = format3.format(new Date());
        System.out.println(timeStr);
        

	}

}
